package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: SetmealController
 * Package: com.sky.controller.user
 * Description:
 *
 * @Author 八云
 * @Create 2025/3/23 0:21
 * @Version 1.0
 */

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api("C端套餐相关接口")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据套餐分类id查询套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据套餐分类id查询套餐")
    @Cacheable(value = "setmealCache", key = "#categoryId")
    public Result<SetmealVO[]> list(Long categoryId) {
        log.info("查询套餐分类:{}", categoryId);
        //查询起售中的套餐
        return Result.success(setmealService.list(Setmeal.builder()
                .status(StatusConstant.ENABLE)
                .categoryId(categoryId)
                .build()));


    }

    /**
     * 根据套餐id查询菜品选项
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询菜品选项")
    @Cacheable(value = "setmealDishCache", key = "#id")
    public Result<DishItemVO[]> getDishItemById(@PathVariable Long id) {
        log.info("查询套餐菜品信息:{}", id);
        DishItemVO[] dishItemVO = setmealService.getByIdWithDishItem(id);
        return Result.success(dishItemVO);
    }
}
